//
//  AppDelegate.m
//  EasyStyle
//
//  Created by FK on 15/12/9.
//  Copyright © 2015年 FK. All rights reserved.
//

#import "AppDelegate.h"
//#import "MMDrawerController.h"
#import "ESRootContainerViewController.h"
#import "MMDrawerVisualState.h"

#import "ESDrawerViewController.h"
#import "ESTabBarViewController.h"

#import "ESNavigationController.h"
#import "ESMainViewController.h"
#import "ESWeiXinSelectedViewController.h"
#import "ESLocationSupport.h"

@interface AppDelegate ()

@property (nonatomic,strong) ESRootContainerViewController * drawerController;

@property (nonatomic,strong) UITabBarController *tabbarController;
@end

@implementation AppDelegate

-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    
    ESDrawerViewController *leftSideDrawerViewController = [[ESDrawerViewController alloc] init];
    ESNavigationController *leftNav = [[ESNavigationController alloc]initWithRootViewController:leftSideDrawerViewController];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ESTabBarViewController *centerViewController = [storyboard instantiateViewControllerWithIdentifier:@"rootTabBarVC"];
    
    self.drawerController = [[ESRootContainerViewController alloc]initWithCenterViewController:centerViewController leftDrawerViewController:leftNav];
    
    [self.drawerController setDrawerVisualStateBlock:[MMDrawerVisualState slideAndScaleVisualStateBlock]];  /// 改变抽屉出现方式
    [self.drawerController setMaximumLeftDrawerWidth:260.0];  /// 抽屉宽度
    self.drawerController.showsShadow = NO;  /// 抽屉阴影
    [self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];  /// 打开抽屉的方式
    [self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];  /// 关闭抽屉的方式
    
    ESNavigationController *rootContainerNav = [[ESNavigationController alloc]initWithRootViewController:self.drawerController];

    rootContainerNav.navigationBar.hidden = YES;
    
    self.window.rootViewController = rootContainerNav;

    return YES;
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    NSLog(@"%@",NSHomeDirectory());
    
    
    
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"everLaunched"]) {
        [[ESLocationSupport sharedInstance]startUpdatingLocation];
        
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"everLaunched"];
        
        NSLog(@"Appdelegate：第一次程序启动");
        
        ESDataController *shareInstance = [ESDataController shareInstance];
        [shareInstance saveHoroscopeConsName:@"天秤座"];
        [shareInstance saveUserCityName:@"北京市"];
        [shareInstance saveTrainStationFromCity:@"北京" andDestination:@"上海"];
        
        
        /// 从本地读取全国市级城市列表到userDefault
        NSError*error;
        //获取文件路径
        NSString *filePath = [[NSBundle mainBundle]pathForResource:@"ChineseCityList"ofType:@"json"];
        
        //根据文件路径读取数据
        NSData *jdata = [[NSData alloc]initWithContentsOfFile:filePath];
        
        //格式化成json数据
        NSArray *jsonObject = [NSJSONSerialization JSONObjectWithData:jdata options:kNilOptions error:&error];
        
        NSMutableArray *allCityArr = [NSMutableArray array];
        
        for (NSDictionary *dict in jsonObject) {
            [allCityArr addObject:[dict objectForKey:@"name"]];
        }
        [[NSUserDefaults standardUserDefaults] setValue:allCityArr forKey:LocateCityList];
        
        [[NSUserDefaults standardUserDefaults]synchronize];
        
    }

    [self.window makeKeyAndVisible];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
